package com.dhcc.DRGsHosp.web.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.dayatang.utils.Page;
import org.openkoala.koala.commons.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.DRGsHosp.core.domain.DrgsVersionManageDTO;
import com.dhcc.DRGsHosp.facade.DrgsVersionManageFacade;



@Controller
@RequestMapping("/DrgsVersionManage")
public class DrgsVersionManageController {

	@Autowired
	private DrgsVersionManageFacade drgsVersionManageFacade;
	
	@ResponseBody
	@RequestMapping("/add")
	public InvokeResult add(String addDate,DrgsVersionManageDTO dvmDTO) {
		//dvmDTO.setAddDate(addDate);
		SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd"); 
		  try {
	            Date date=sDateFormat.parse(addDate);
	            dvmDTO.setAddDate(date);
	        } catch(ParseException px) {
	            px.printStackTrace();
	        }
		 
		return drgsVersionManageFacade.creatDrgsVersionManage(dvmDTO);
	}
	
	@ResponseBody
	@RequestMapping("/update")
	public InvokeResult update(Date addDate,DrgsVersionManageDTO dvmDTO) {
		/*SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd"); 
		  try {
	            Date date=sDateFormat.parse(addDate);*/
	            dvmDTO.setAddDate(addDate);
	        /*} catch(ParseException px) {
	            px.printStackTrace();
	        }*/
		return drgsVersionManageFacade.updateDrgsVersionManage(dvmDTO);
	}
	
	@ResponseBody
	@RequestMapping("/pageJson")
	public Page pageJson(DrgsVersionManageDTO dvmDTO, @RequestParam int page, @RequestParam int pagesize) {
		Page<DrgsVersionManageDTO> all = drgsVersionManageFacade.pageQueryDrgsVersionManage(dvmDTO, page, pagesize);
		return all;
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public InvokeResult remove(@RequestParam String verCodes) {
		String[] value = verCodes.split(",");
        String[] idArrs = new String[value.length];
        for (int i = 0; i < value.length; i ++) {
        					idArrs[i] = value[i];
			        				        }
        return drgsVersionManageFacade.removeDrgsVersionManages(idArrs);
	}
	
    @InitBinder    
    public void initBinder(WebDataBinder binder) {  
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");    
        dateFormat.setLenient(false);    
        //CustomDateEditor 可以换成自己定义的编辑器。
        //注册一个Date 类型的绑定器 。
        binder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
    
    /**
     *  
     *  isHospOrderExist.  
     *  @Description：院区编码是否存在
     *  @Author fulianxia
     *  @param hospOrder
     *  @return 
     *  @Date:2018年3月26日
     */
    @ResponseBody
    @RequestMapping("/isVerOrderExist")
    public boolean isVerOrderExist(String verCode) {
    	return  drgsVersionManageFacade.isVerOrderExist(verCode);
    }
	
}
